package com.atg.ai_agent.rag.config;


import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
import com.alibaba.cloud.ai.dashscope.rag.DashScopeDocumentRetriever;
import com.alibaba.cloud.ai.dashscope.rag.DashScopeDocumentRetrieverOptions;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.chat.client.advisor.api.Advisor;
import org.springframework.ai.rag.retrieval.search.DocumentRetriever;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/*
author: atg
time: 2025/9/19 18:29
*/

// 云向量化存储

@Configuration
public class LoveCloudRagAdvisorsConfig {

//    @Value("spring.ai.dashscope.api-key")
    @Value("${spring.ai.dashscope.api-key}")
    private String dashScopeApi;
    private static final String indexName = "恋爱知识库";

    @Bean
    public Advisor loveCloudRagAdvisors() {
        DashScopeApi dashScopeApi = new DashScopeApi(this.dashScopeApi);
        DocumentRetriever retriever = new DashScopeDocumentRetriever(dashScopeApi,
                DashScopeDocumentRetrieverOptions.builder().withIndexName(indexName).build());
        return RetrievalAugmentationAdvisor.builder()
                .documentRetriever(retriever).build();
    }
}
